<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-08-31 11:00:35
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" other
-->

<template>
	<el-row style="height: 100%">
		<el-col :span="11" style="height: 100%">
			<sc-VxeTable ref="xGrid" :gridEvts="gridEvents" :tablecode="'pro_pot_dyekk'" :url="api.pro.pot.list"
				:params="getParams">
			</sc-VxeTable>
		</el-col>
		<el-col :span="13" style="height: 100%;">
			<sc-VxeTable ref="xGridLoom" :tablecode="'pro_plan_loom'" :gridOps="gridOps" :gridEvts="rightgridEvents"
				:url="api.report.loom.list" :children="{
			tablecode: 'pro_plan_kk_pot',
			url: api.pro.pot.list,
			gridOps: {
				rowClassName: subRowClass
			},
			params: { process_id: { type: 'in', value: [10, 3, 4, 5] }, 'is_kk': 1 },
			key: 'loom_id',
		}"></sc-VxeTable>
		</el-col>
	</el-row>
	<save-dig v-if="dialog.save" ref="save" @success="handleSuccess" @closed="dialog.save = false"></save-dig>
</template>

<script>
export default {
	name: "pro_pot_dyekk",
};
</script>

<script setup>
import { nextTick, ref } from "vue";
import { ElMessageBox } from "element-plus";
import saveDig from "./save";
import api from "@/api";
import tool from "@/utils/tool";
const dialog = ref({
	save: false,
});
const xGrid = ref({});
const xGridLoom = ref({});
const save = ref({});
const handleSuccess = () => {
	xGrid.value.refresh();
	xGridLoom.value.refresh();
};
const gridOps = {
	columns: [
		{
			field: "bfcount",
			className: "red",
		},
		{
			field: "bfquntity",
			className: "red",
		},
	],

	cellClassName: ({ column, row }) => {
		if (column.field == 'code' && row.process_id != 3) {
			return 'backgroudBlue';
		}
	}
};
const subRowClass = ({ row }) => {
	let time = new Date(row.potdate).getTime();
	let nowtime = new Date(tool.SYS_DATE()).getTime();
	if (time < nowtime)
		return 'backgroudRed'
}
// rowClassName: (data) => {
// 		console.log(data);
// 	},
const openEdit = (row) => {
	dialog.value.save = true;
	nextTick(() => {
		save.value.setData(row, row.is_kk == 0).open();
	});
}
const params = ref(null);
const getParams = () => {
	if (params.value) {
		return params.value;
	}
}
const rightgridEvents = {
	cellDblclick: function ({ row }) {
		params.value = { loom_id: row.id };
		xGrid.value.refresh().then(() => params.value = null);
	},
}
const gridEvents = {
	edit: ({ button }) => {
		openEdit(button.selectRecords[0]);
	},
	cellDblclick: function ({ row }) {
		openEdit(row);
	},
	nosaveDyePlan: ({ button }) => {
		return ElMessageBox.confirm(
			"您确定要取消开卡?"
		).then((type) => {
			if (type === "confirm") {
				return api.pro.pot.nosaveDyePlan.post({ ids: button.selectRecords.map((v) => v.id) });
			}
		})
	},
	reload: () => {
		xGridLoom.value.refresh();
	}
};
</script>
